package Receive;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class Receive_Packet {
	public int length;
	public byte result;
	
	protected Receive_Packet (byte[] packet) {
		byte[] temp_length = new byte[4];
		System.arraycopy(packet, 0, temp_length, 0, 4);
		this.length = byteToint(temp_length);
		this.result = packet[4];
	}

	protected int byteToint(byte[] bytes) {
		ByteBuffer buff = ByteBuffer.allocate(Integer.SIZE / 8);
		buff.order(ByteOrder.LITTLE_ENDIAN);
		buff.put(bytes);
		buff.flip();
		return buff.getInt();
	}
	
	protected float byteTofloat(byte[] bytes) {
		ByteBuffer buff = ByteBuffer.allocate(Float.SIZE / 8);
		buff.order(ByteOrder.LITTLE_ENDIAN);
		buff.put(bytes);
		buff.flip();
		return buff.getFloat();
	}
}
